package com.learn.xueer.ui.activity

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import androidx.lifecycle.Observer
import com.learn.xueer.R
import com.learn.xueer.app.base.BaseActivity
import com.learn.xueer.app.util.CacheDataManager
import com.learn.xueer.databinding.ActivityMemberCenterBinding
import com.learn.xueer.ui.adapter.BookSectionAdapter
import com.learn.xueer.ui.adapter.VipAdapter
import com.learn.xueer.ui.viewmodel.MineViewModel
import kotlinx.android.synthetic.main.activity_member_center.rv_vip
import me.hgj.jetpackmvvm.util.ActivityMessenger
import me.hgj.jetpackmvvm.util.startActivity

/**
 * 会员中心
 */
class MemberCenterActivity : BaseActivity<MineViewModel, ActivityMemberCenterBinding>() {

    /**
     * 未购买取mouth   price   价格
     * 已购买显示pramsjson 中的价格
     */
    private val vipAdapter: VipAdapter by lazy { VipAdapter(arrayListOf()) }

    override fun createObserver() {
        rv_vip.adapter = vipAdapter
        mDatabind.click = ProxyClick()
        mViewModel.vip.observe(this, Observer {
            vipAdapter.setList(it.list)
        })
        vipAdapter.setOnItemClickListener { baseQuickAdapter, view, i ->

            ActivityMessenger.startActivity<ServiceDetailActivity>(this, "id" to vipAdapter.data[i].id.toString(),"grade" to vipAdapter.data[i].grade_type )
        }
    }

    inner class ProxyClick {


        fun myOrder() {
            startActivity(MyOrderActivity::class)
        }

        fun back() {
            finish()
        }


    }

    override fun initView(savedInstanceState: Bundle?) {
        mDatabind.click = ProxyClick()
        mViewModel.vipReq()
    }
}